﻿using System;

namespace OpenLS.Drawing.UI.Internals
{
    internal class ShapeLineFillFormatter : ShapeFillFormatterBase
    {
        public ShapeLineFillFormatter(IShape shape):base (shape) 
        {
        }
        public override ColorBase SelectedColor
        {
            get
            {
                if (Model.ShapeProperties == null)
                    return null;
                if (Model.ShapeProperties.LineProperties == null)
                    return null;
                SolidColorFillProperties p = Model.ShapeProperties.LineProperties.LineFillProperties as SolidColorFillProperties;
                if (p == null)
                    return null;
                return p.Color;
            }
            set
            {
                if (value == null)
                {
                    if (EnsureShapeProperties().LineProperties != null)
                        EnsureShapeProperties().LineProperties.LineFillProperties = null;
                }
                else
                    EnsureShapeProperties().EnsureLineProperties().LineFillProperties = new SolidColorFillProperties(value);
            }
        }


        protected override Type GetFillType()
        {
            if (Model.ShapeProperties == null)
                return null;
            if (Model.ShapeProperties.LineProperties == null)
                return null;
            if (Model.ShapeProperties.LineProperties.LineFillProperties == null)
                return null;
            return Model.ShapeProperties.LineProperties.LineFillProperties.GetType();
        }

        protected override void SetFill(LineFillProperties fill)
        {
            if (EnsureShapeProperties().LineProperties == null)
                EnsureShapeProperties().LineProperties = new LineProperties();
            EnsureShapeProperties().LineProperties.LineFillProperties = fill;

        }
    }
}